package com.khshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khshop.pojo.Role;
import com.khshop.mapper.RoleMapper;
import com.khshop.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.khshop.vo.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired(required = false)
    RoleMapper roleMapper;

    @Override
    //新增按钮权限
    public ServiceResult<Role> addRole(Role role) {
        return ServiceResult.of(roleMapper.insert(role)>0);
    }

    @Override
    //修改按钮权限
    public ServiceResult<Role> updateRole(Role role) {
        return ServiceResult.of(roleMapper.updateById(role)>0);
    }

    @Override
    //删除按钮权限
    public ServiceResult<Role> delRole(Integer id) {
        return ServiceResult.of(roleMapper.deleteById(id)>0);
    }

    @Override
    //查询按钮权限
    public ServiceResult<IPage<Role>> searchRole(Map<String, String> map, Integer page, Integer limit) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        queryWrapper.allEq(map);
        Page<Role> iPage = new Page<Role>(page, limit);
        IPage<Role> orderIPage = roleMapper.selectPage(iPage, queryWrapper);
        return ServiceResult.of(orderIPage,orderIPage.getSize()>0);
    }
}
